/**
 * 这里按需引入lodash的一些方法,方便维护
 */

import { isObject } from './is';

//  export  {default as xxx} from 'lodash/xxx'

export { default as cloneDeep } from 'lodash/cloneDeep';
export { default as intersection } from 'lodash/intersection';
export { default as get } from 'lodash/get';
export { default as upperFirst } from 'lodash/upperFirst';
export { default as omit } from 'lodash/omit';
export { default as debounce } from 'lodash/debounce';
export { default as has } from 'lodash/has';
export { default as merge } from 'lodash/merge';
export { default as uniqueId } from 'lodash/uniqueId';

export default function toCase(str:string) {
  const to = str.replace(/(-[a-z])/g, function (v) {
    return v.replace('-', '').toLocaleUpperCase();
  });

  return lower(to);
}

export function lower(str:string) {
  return str.replace(str[0], str[0].toLowerCase());
}

export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
  let key: string;
  for (key in target) {
    src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
  }
  return src;
}
